﻿Ext.define('Happy.navigation.shell.view.LoginWindow', {
    extend: 'Ext.window.Window',
    alias: 'widget.shell-login-window',
    requires: [
        'Happy.form.Panel',
        'Happy.Ajax'
    ],

    title: '登陆窗口',
    modal: true,
    closable: false,
    layout: 'fit',

    initComponent: function () {
        var me = this;

        Ext.apply(me, {
            items: {
                xtype: 'happy-form',
                defaultType: 'textfield',
                fieldDefaults: {
                    labelAlign: 'right',
                    labelWidth: 80
                },
                items: [
                    {
                        fieldLabel: '用户名',
                        name: 'username',
                        allowBlank: false
                    },
                    {
                        fieldLabel: '密码',
                        name: 'password',
                        inputType: 'password',
                        allowBlank: false
                    }
                ],
                buttons: [
                    {
                        text: '登陆',
                        handler: Ext.bind(me.on_Login_Click_Handler, me)
                    }
                ]
            }
        });

        me.callParent(arguments);
    },

    on_Login_Click_Handler: function () {
        var me = this;
       
        Happy.Ajax.callAction({
            url: '/Happy/Security/Authenticate/Login',
            params: me.down('form').getValues(),
            success: function (result) {
                if (result.isAuthenticated) {
                    me.fireEvent('authenticatesucces', me, result);
                    me.close();
                }
            }
        });
    }
});